package com.sy.simpleegg.mvp.presenter

import androidx.lifecycle.LifecycleCoroutineScope
import com.sy.simpleegg.base.BasePresenter
import com.sy.simpleegg.mvp.contract.LogManageContract
import com.sy.simpleegg.mvp.model.LogManageModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class LogManagePresenter(private val lifecycleCoroutineScope: LifecycleCoroutineScope): BasePresenter<LogManageContract.Model, LogManageContract.View>(), LogManageContract.Presenter {

    override fun createModel(): LogManageContract.Model = LogManageModel()
    override fun getLogDirs() {
        val dateArr = mModel?.getLogDirs()
        mView?.refreshSpinner(dateArr)
    }

    override fun uploadLog(date: String) {
        lifecycleCoroutineScope.launch {
            mView?.showUploading(0)
            var result = 0
            withContext(Dispatchers.IO){
                result = mModel?.uploadLog(date)?: 2
            }
            mView?.showUploading(result)
        }
    }


}